import { testDao } from "#/dao";
import type { Test } from "#/types";
import { getUuid, getCurrentTime, logger } from "#/utils";

export async function queryList(type: number) {
  try {
    return await testDao.queryList(type);
  } catch (error) {
    logger(error);
  }
}

export async function insert(data: Test) {
  try {
    const rank = await testDao.getRank();
    return await testDao.insert({
      ...data,
      id: getUuid(),
      source: 0,
      createTime: getCurrentTime(),
      rank,
    });
  } catch (error) {
    logger(error);
  }
}

export async function deleteById(id) {
  try {
    return await testDao.deleteById(id);
  } catch (error) {
    logger(error);
  }
}

export async function update(data: Test) {
  try {
    return await testDao.update(data);
  } catch (error) {
    logger(error);
  }
}
export async function queryById(id: number) {
  try {
    return await testDao.queryById(id);
  } catch (error) {
    logger(error);
  }
}
export default {
  queryList,
  insert,
  deleteById,
  update,
  queryById,
};
